$(document).ready(function() {
	$('.extraInfo').each(function(index, element){
		$(this).mouseout(function(){hideExtraTitle();}); 
		$(this).mouseover(function(){showExtraTitle(this,$(this).attr('title'));});
	});
});



//check if attribute is supported in browser
function IsAttributeSupported(tagName, attrName) 
{
    var val = false;
    // Create element
    var input = document.createElement(tagName);
    // Check if attribute (attrName)
    // attribute exists
    if (attrName in input) 
    {
        val = true;
    }
    // Delete "input" variable to
    // clear up its resources
    delete input;
    // Return detected value
    return val;
}



function checkForm(form) 
{
	var strError = "";
	var submit = false;
	$(":input").each(function() 
	{
	    if($(this).attr('required') != null)
	    {
	    	if(!checkRequiredInput(this.id, true))
	    		submit = false;
	    }
	});
	
	if(submit == false)
		return false;
	else 
		return true;
}

function submitForm(form, table)
{
	
	
}


function checkRequiredInput(id, checkSupported)
{
	var retVal = true;
	var supported = false;
	
	if(checkSupported)
		supported = IsAttributeSupported('input', 'required'); 
	
	if(!supported)
	{
		var inputValue = $('#'+id).val();
		var error = '';	
		$('#'+id+'Error').remove();
		
		//input == empty
		if(inputValue == '')
			error = 'Dit is een verplicht veld.';
		
		//not empty, other checks
		else
		{
			//email
			if(id == 'email')
			{
				//error = checkEmail(inputValue);
			}
		}
	
		//display error
		if(error != '')
		{
			$('#'+id).after('<div class="inputError" id="'+id+'Error">'+error+'</div>');
			retVal = false;
		}
		else
			retVal = true;
	}
	return retVal;
}

function checkEmail(input)
{
	$.ajax(
	{
		url: 'factory/checkEmail.php',
		type: "POST",
		data: {email: input},
		success: function(retVal)
		{
			if(retVal != '')
			{
				alert('retval:'+retVal);
				return retVal;
			}
		}
	});
}


function openPopup(link, titel, breedte, hoogte) {
	if (!$(".popup").length) {
		$('#main_container').append('<div class="popup"></div>');
	}
	$(".popup").dialog('destroy');
	$(".popup").dialog({
		title : titel,
		width : breedte,
		height : hoogte,
		modal : true,
		autoOpen : false,
		open : function(event, ui) {
			$(".popup").load(link);
		}
	});
	$(".popup").dialog("open");
	return false;
}
function showExtraTitle(e, msg) {
	if (!$("#messageBox").length)
		$('#main_container').append('<div id="messageBox"></div>');
	var relativeX = $(e).offset().left + 20;
	var relativeY = $(e).offset().top - 40;
	$('#extramessageBox').css({
		top : relativeY,
		left : relativeX + 5
	});
	$('#extramessageBox').html(msg);
	$('#extramessageBox').toggle(true);
}
function hideExtraTitle() {
	$('#extramessageBox').toggle(false);
}
